// import router from ".";

let tree = [
    {
        id:1,
        title:'主页',
        children:[
            {
                id:3,
                pid:1,
                title:'欢迎',
            },
            {
                id:4,
                pid:1,
                title:'学员管理',
                children:[
                    {
                        id:5,
                        pid:4,
                        title:'测试'
                    }
                ]
            }
        ]
    },
    {
        id:2,
        title:'用户中心'
    }
]


function repeatTree(data){
    let repeatArr = [];
    function recursion(data){
        data.forEach(item => {
            if(item.children){
                recursion(item.children)
            }
            repeatArr.push({
                id:item.id,
                title:item.title,
                pid:item.pid ?? ""
            })
        })
    }
    recursion(data)
    return repeatArr
}
let res = repeatTree(tree)
// console.log(res);



function convertTree(repeatArr){
    let tree = [];
    repeatArr.forEach(item => {
        let parent = repeatArr.find(v => item.pid === v.id)
        // console.log(parent);
        if(parent){
            if(!parent.children){
                parent.children = [];
            }
            // item.path = item.path.split('/').pop()
            // console.log(item);
            // console.log(item.path);
            parent.children.push(item)
        }else{
            tree.push(item)
        }
    })
    return tree
}
let res2 = convertTree(res)
// console.log(res2);